/**
 * Created by lx on 2017/3/11.
 */
angular.module('service.advertisement',[
    "ngResource",
])
    .service('advertisementService',['$resource',function($resource){
       this.putad=function(data,success,error){
           var resource=$resource(marketurl+"adv");
           return resource.save(data,success,error);
       };
        //增加adv
        this.add = function (adv, success, error) {
            var resource = $resource(marketurl + "adv");
            return resource.save({}, adv, success, error);
        };
        //获取所有有效adv
        this.queryAllAdv = function () {
            var resource = $resource(marketurl + "adv/byexist");
            return resource.query();
        };
        //通过用户id获取所有有效adv
        this.getAdvById = function (uid) {
            var resource = $resource(marketurl + "adv/allbycid/:uid");
            return resource.query({uid: uid});
        };
        //通过广告id获取广告
        this.getAdvByAdvId = function (advid) {
            var resource = $resource(marketurl + "adv/:advid");
            return resource.get({advid: advid});
        };
        //通过广告id删除广告
        this.removeByAdvid = function (advid,succuss,error) {
            var resource = $resource(marketurl + "adv/:advid");
            return resource.remove({advid: advid},succuss,error);
        };
        //通过广告id更新广告
        this.updataByAdvid = function (adv,succuss,error) {
            var resource = $resource(marketurl + "adv/:advid");
            return resource.save({advid: adv.aId},adv,succuss,error);
        };
        //通过广告id获取无效关联超市
        this.invalidrelByAdvid = function(advid){
            var resource = $resource(marketurl + "invalidrel/aidall/:advid");
            return resource.query({advid: advid});
        };
        //通过广告id获取有效关联超市
        this.relationByAdvid = function(advid){
            var resource = $resource(marketurl + "relation/aidall/:advid");
            return resource.query({advid: advid});
        };
    }])
